﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Top.Data;

namespace Top.PointStore.Business
{
    public static class BlacklistManager
    {
        public static async Task<bool> Add(string code)
        {
            const string sql="INSERT INTO blacklist(F_Code,F_BrokerCompanyKid) (SELECT F_Code ,Kid as F_BrokerCompanyKid FROM t_brokercompany WHERE F_Code={0} GROUP BY F_Code);";
            using (var db = DataBaseContext.GetDataBase("write"))
            {
                if(!string.IsNullOrEmpty(code))
                {
                    return await db.Sql(sql).ExecuteNonQuery() > 0;
                }
            }
            return false;
        }
        public static async Task<bool> Exist(int brokerId)
        {
            const string sql = "SELECT Count(1) FROM blacklist WHERE F_BrokerCompanyKid=(SELECT F_BrokerCompanyKid FROM t_broker WHERE Kid={0});";
            using(var db=DataBaseContext.GetDataBase("reader"))
            {
                if(brokerId>0)
                {
                    return await db.Sql(sql, brokerId).ExecuteScalar<int>() > 0;
                }
            }
            return false;
        }
    }
}
